<?php
include_once 'Element.php';

/**
 * CheckBox HTML
 */
class CheckBox extends Element {
    
    private $checked;
    private $value;
    private $label;
    private $disabled;
  
    /**
     * Constructor
     * @param String $id identificador del CheckBox
     * @param Boolean $value Valor de Checked
     */
    public function __construct($id, $value = FALSE) {
        parent::__construct($id);
        $this->value = $value;
    }

    /**
     * Genera el Código HTML del CheckBox
     * @return type
     */
    public function generate() {
        $html = array();
        $name = parent::getId();
        
        $value = '';
        if($this->value) {
            $value = 'value="'.$this->value.'"';
        }
        
        $checked = '';
        if($this->checked) {
            $checked = 'checked';
        }
        
        $label = $this->label;
        
        
        if ($this->disabled)
            $visibility = "disabled='true'";
        else
            $visibility = '';

        $html[] = "<input $checked $value $visibility style='' id='$name' name='$name' type='checkbox'>$label <br>";


        $output = '';
        foreach ($html as $code) {
            $output = $output . $code;
        }
        return (String) $output;
    }

    
    /**
     * Obtiene la Etiqueta del CheckBox
     * @return String Etiqueta
     */
    public function getLabel() {
        return $this->label;
    }

    /**
     * Establece la Etiqueta del CheckBox
     * @param String $lebel
     */
    public function setLabel($lebel) {
        $this->label = $lebel;
    }

    
    /**
     * Obtiene el estado de Disabled del CheckBox
     * @return Boolean
     */
    public function getDisabled() {
        return $this->disabled;
    }

    /**
     * Establece el estado de Disabled del CheckBox
     * @param Boolean $disabled
     */
    public function setDisabled($disabled) {
        $this->disabled = $disabled;
    }
    
    /**
     * Obtiene el Valor del CheckBox
     * @return String
     */
    public function getValue() {
        return $this->value;
    }

    /**
     * Establece el valor del CheckBox
     * @param String $value
     */
    public function setValue($value) {
        $this->value = $value;
    }
    
    /**
     * Obtiene el Valor de Tildado del CheckBox
     * @return Boolean
     */
    public function getChecked() {
        return $this->checked;
    }

    /**
     * Establece el Valor de Tildado del CheckBox
     * @param Boolean $checked
     */
    public function setChecked($checked) {
        $this->checked = $checked;
    }

}

?>
